<?php
/**
 * +--------------------------------------------------------+
 * @Created by PhpStorm.
 * @Category LoginController.php
 * @Depiction:
 * Author: hwy
 * Date: 2020/5/28  16:45
 * +--------------------------------------------------------+
 */

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;

class LoginController extends Controller
{
    public function __construct()
    {
        $this->middleware('guest:admin')->except('logout');
    }

    public function login(Request $request){

        return view('admin.login.login');
    }

    public function loginHandle(Request $request){
        $this->validate($request,[
            'username'   =>  'required',
            'password'   =>  'required',
        ]);

        if(Auth::guard('admin')->attempt(['name'=>$request->username, 'password' => $request->password])) {
            $log['user_name'] = Auth::guard('admin')->user()->username;
            $log['ip'] = request()->getClientIp();
            $log['model'] = '登录';
            $log['action'] = '登录';
            $log['type'] = 4;
            $log['content'] = '登录';
            $log['status'] = 1;
//            $add = AdminLog::create($log)->id;


            return ['code' => 0, 'message' => '登陆成功'];
        }else{
            return ['code' => -1, 'message' => '账号或者密码错误'];
        }
    }


}
